package com.yty.demo._12_io;

import java.io.*;

/**
 * @author: yangtaoyao
 * @time: 2020/1/16 13:54
 * @description: 标准输入输出流
 */
public class SystemIO {
    public static void main(String[] args) {
        //testSystemIn();
        String tpath="D:\\IdeaProjects\\javaStudy-demo\\src\\com\\yty\\demo\\_12_io\\txt\\testWriterTXT.txt";
        testWriterTXT(tpath);
    }

    public static void testSystemIn() {
        try {
            InputStreamReader in=new InputStreamReader(System.in);
            BufferedReader br=new BufferedReader(in);
            String s="";
            while (!((s=br.readLine())!=null)){
                System.out.println(s);
            }
            br.close();
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 控制台输入写入到文件
     */
    public static void testWriterTXT(String tpath) {
        try {
            InputStreamReader in=new InputStreamReader(System.in);
            BufferedReader br=new BufferedReader(in);
            BufferedWriter out=new BufferedWriter(new FileWriter(tpath));

            String line="";
            while ((line=br.readLine())!=null){
                if(line.equals("over")){
                    break;
                }
                out.write(line);
            }
            out.flush();
            out.close();
            br.close();
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
